<template>
    <div class="container">
        <div class="user-info">
          <div class="info">
              <span class="title">塘栖数字农业大脑欢迎您</span>
              <span class="user">{{getUserInfo()}}</span>
          </div>
           <div class="oper">
               <span style="margin-right:20px" @click="accountManagement" v-if="userInfo().username==='admin'">账号管理</span>
               <span style="margin-right:20px" @click="changePassword">修改密码</span>
               <span @click="handleLogout">退出登录</span>
           </div>
        </div>
        <div class="sys">
            <a-row>
                <template v-for="(item,index) in sysList">
                    <a-col :sm="24" :md="12" :lg="8" :key="index">
                        <div 
                         :key="index"
                        class="sys-item" 
                        @click="systemPath(item)"
                        :style="{background:'url('+item.background+') 0% 0% / 100% no-repeat'}"
                        >
                            <div class="name">
                                {{item.name}}
                                <div class="line" />
                            </div>
                        </div>
                    </a-col>
                </template>
            </a-row>
        </div>
       <user-password ref="userPassword"></user-password>
    </div>
</template>
<script>
//   import screenWrap from './screenWrap.vue'
  import UserPassword from '@/components/tools/UserPassword.vue'
  import { mapActions, mapGetters } from 'vuex'
  import {queryTqppSystemList,getLoginMsg} from '@/api/system'
  import {getDataScreenToken} from '@/api/dashboards'
  import { ISTHRID } from '@/store/mutation-types'
  import Vue from 'vue'
    export default {
      name: 'homes',
      components: {
    //   screenWrap,
      UserPassword
     },
      data(){
          return{
              sysList:[],
              showMask:false,
          }
      },
      mounted(){
          this.queryTqppSystemList()
          console.log(Vue.ls.get(ISTHRID),'ISTHRID');
      },
      methods:{
          ...mapActions(['Logout']),
          ...mapGetters(['nickname', 'avatar', 'userInfo','subjectName','subjectId']),
          getUserInfo(){
              if(this.userInfo().username==='admin'){
                  return '超级管理员' + '-' + this.userInfo().username
              }else{
                  if(this.subjectName()){
                    return this.subjectName() + '-' + this.userInfo().username
                  }
              }
          },
          handleLogout() {
          const that = this
          this.$confirm({
              title: '提示',
              content: '真的要注销登录吗 ?',
              onOk() {
              return that.Logout({}).then(() => {
                  // update-begin author:wangshuai date:20200601 for: 退出登录跳转登录页面
                  if(Vue.ls.get(ISTHRID)==='ISTHRID'){
                    that.$router.push({ path: '/user/companyLogin' })
                  }else{
                    that.$router.push({ path: '/user/login' })
                  }
                  // window.location.reload()
                  // update-end author:wangshuai date:20200601 for: 退出登录跳转登录页面
              }).catch(err => {
                  that.$message.error({
                  title: '错误',
                  description: err.message
                  })
              })
              },
              onCancel() {
              }
          })
          },
          async getDataScreenToken(subjectId) { //获取耘田token
             let res = await getDataScreenToken({subjectId:subjectId})
             if(res.success){
                window.open(`http://8.140.154.124:10203/ssoLogin?type=2&token=${res.result.token}&accountId=${res.result.accountId}`)
              }else {
                this.$message.warning(res.message)
              }
          },
          async getLoginMsg() { //经纪人系统token
             let res = await getLoginMsg()
             if(res.success){
                if (process.env.NODE_ENV === 'production'){
                    window.open(`http://broker.tqpp-prod.iot-farm.cn/styz/login/single_login?login_token=${res.result}`)
                }else{
                    window.open(`http://xyjjjrglxt.zji.cn/styz/login/single_login?login_token=${res.result}`)
                }
              }else {
                this.$message.warning(res.message)
              }
          },
            // 获取系统列表
          async queryTqppSystemList() {
              try {
                  const res = await queryTqppSystemList()
                  this.sysList = res.result&&res.result.length&&res.result
                  this.sysList.map(item=>{
                      item.background = require(`@/assets/system/${item.code}.png`)
                  })
                  console.log(this.sysList);
              } catch (error) {
                  console.log(error);
              }
          },
          changePassword(){
              const username = this.userInfo().username
              this.$refs.userPassword.show(username)
          },
          getImg(item){
              return require(`@/assets/system/${item.code}.png`)
          },
          systemPath(data) {
              console.log(data);
              if(data.code==="sznc"){
                if (process.env.NODE_ENV === 'production'){
                   window.open('http://223.4.69.216/os/oauth/authorize?response_type=code&scope=read&client_id=ogIVZtBxKOCtFrhbhlp7&redirect_uri=https://tqppszt.linping.gov.cn/ssoLogin/?type=1&state=1234')
                   return
                }else{
                   window.open('http://223.4.69.216/os/oauth/authorize?response_type=code&scope=read&client_id=T1ha9ULadVlQIDhunTHg&redirect_uri=http://8.140.154.124:10203/ssoLogin/?type=1&state=1234')
                   return
                }
              }else if(data.code==="jjrjgxt"){
                 this.getLoginMsg()
                 return
              }else if(data.code==="gszyglxt"){
                  window.open('/fruiter-web/Orchard/OrchardManagement')
                   return
              }else if(data.code==="dpsjwh"){
                window.open('/fruiter-web/dpp/villageIndustryList')
                 return
              }else if(data.code==="szdp"){
                  if(data.specification===1){
                    window.open('/fruiter-web/dashBoards')
                     return
                  }else{
                    window.open('/fruiter-web/hallDashBoards')
                     return
                  }
              }
          },
          accountManagement(){
               window.open('/fruiter-web/account/management')
              // this.$router.push({ path: '/account/management' })
          }
      },
    }
</script>
<style lang="less" scoped>
  .container{
      ::-webkit-scrollbar{
          display: none;
      }
      -ms-overflow-style: none;
      scrollbar-width: none;
      min-height: 100%;
      background: url('../../assets/system/bg.png') no-repeat;
      background-size:100% 100%;
      background-attachment:fixed;
      .user-info{
          padding: 30px 50px;
          display: flex;
          align-items: center;
          justify-content: space-between;
          .info{
              .title{
                  font-size: 48px;
                  font-family: Helvetica;
                  color: #FFFFFF;
              }
              .user{
                  font-size: 20px;
                  font-weight: 500;
                  color: #FFFFFF;
                  margin-left: 20px;
              }
          }
          .oper{
              cursor: pointer;
              font-size: 16px;
              font-weight: 500;
              color: #FFFFFF;
          }
      }
      .sys{
          display: block;
          width: 85%;
          max-height:100%;
          margin: 0 auto;
          padding-top: 3%;
          .sys-item{
              max-width:440px;
              height: 280px;
              margin-right:16%;
              margin-bottom:5%;
              position: relative;
              cursor: pointer;
              .name{
                  padding: 10% 0 0 48px;
                  max-width: 288px;
                  font-size: 36px;
                  font-family: PingFangSC-Medium, PingFang SC;
                  font-weight: 500;
                  color: #FFFFFF;
                  position: relative;
                  .line{
                  width: 120px;
                  height: 8px;
                  background: #FFFFFF;
                  border-radius: 4px;
                  margin-top: 24px;
                }
              }
            
          }
      }
      .mask{
          position: absolute;
          top: 0;
          left: 0;
          bottom: 0;
          right: 0;
          width: 100%;
          height: 100%;
          background: #7B7B7C;
      }
  }
</style>